package com.voto.sunflower.activity.me;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.voto.sunflower.R;
import com.voto.sunflower.activity.BaseActivity;

public class AboutusActivity extends BaseActivity implements OnClickListener {
	private final static int UPDATE_VERSION_RESULT = 0;
	private String version;
	private TextView versionTextView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_me_about_us_detail);
		
		version = getIntent().getStringExtra("version");

		findViewById(R.id.about_us_check_update).setOnClickListener(this);
		versionTextView = (TextView) findViewById(R.id.version);
		versionTextView.setText(version);

		initTitle();
	}

	// 初始化标题栏
	private void initTitle() {
		// 设置标题
		TextView title = (TextView) findViewById(R.id.title);
		TextView back = (TextView) findViewById(R.id.back);

		title.setText(getString(R.string.me_about_us));
		back.setText(getString(R.string.me_main_setting));
		back.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.about_us_check_update:
			updateVersion(version);
			break;
		case R.id.back:
			finish();
			break;
		default:
			break;
		}
	}

	/**
	 * 版本更新
	 */
	private void updateVersion(String version) {
		// 进度圈
		Intent intent = new Intent(AboutusActivity.this, UpdateActivity.class);
		Bundle bundle = new Bundle();
		bundle.putString("version", version);
		intent.putExtras(bundle);
		startActivityForResult(intent, UPDATE_VERSION_RESULT);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == Activity.RESULT_OK) {
			if (requestCode == UPDATE_VERSION_RESULT) {
				if (data != null
						&& data.getExtras().getString("version") != null) {
					versionTextView.setText(data.getExtras().getString(
							"version"));
				}
			}
		}
	}
}
